package it.polimi.meteocal.ejb.invitationmanagement;


import it.polimi.meteocal.ejb.invitationmanager.InvitationDTO;
import it.polimi.meteocal.ejb.usermanagement.User;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Entity implementation class for Entity: PacchettoEntity
 *
 */
@Entity
@Table(name="Invitation")
@NamedQueries({
	@NamedQuery(name=Invitation.FIND_ALL,
				query="SELECT i FROM Invitation i "),
	@NamedQuery(name=Invitation.findUserInvitation,
				query="SELECT i FROM Invitation i WHERE i.user IN (SELECT u FROM User u WHERE u.email = :email) AND i.state = '1'"),
	@NamedQuery(name=Invitation.findEventInvitation,
				query="SELECT i FROM Invitation i WHERE i.eventid = :eventid AND (i.state = 'a' OR i.state = '1')")
})

public class Invitation {

	public Invitation() {
		super();
	}

	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Invitation.findAll";
	public static final String findUserInvitation = "Invitation.findUserInvitation";
	public static final String findEventInvitation = "Invitation.findEventInvitation";
	
	@Id
	@GeneratedValue (strategy=GenerationType.IDENTITY)
	private int invitationid;
	
	private String title;
	
	private String state;
	
	private int eventid;
	
	/*@ManyToMany(mappedBy="invitations")
	  private List<User> users;
	*/
	
	@ManyToOne
	@JoinTable(name = "ihasUser",
		inverseJoinColumns={@JoinColumn(name="userEmail",referencedColumnName="email")}, joinColumns={@JoinColumn(name="invitationid", referencedColumnName="invitationid")})
	private User user;

	public Invitation(InvitationDTO nuovo){
        
        this.invitationid		= nuovo.getInvitationid();
        this.title				= nuovo.getTitle();
        this.state   			= nuovo.getState();
        this.eventid			= nuovo.getEventid();
        
    }

	

	public int getInvitationid() {
		return invitationid;
	}



	public void setInvitationid(int invitationid) {
		this.invitationid = invitationid;
	}



	public String getTitle() {
		return title;
	}



	public void setTitle(String title) {
		this.title = title;
	}



	public String getState() {
		return state;
	}



	public void setState(String state) {
		this.state = state;
	}



	public int getEventid() {
		return eventid;
	}



	public void setEventid(int eventid) {
		this.eventid = eventid;
	}



	public User getUser() {
		return user;
	}



	public void setUser(User user) {
		this.user = user;
	}



	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public static String getFindAll() {
		return FIND_ALL;
	}

	public static String getFinduserinvitation() {
		return findUserInvitation;
	}
	
	

	
	
	
	
}
